import Vue from 'vue'
import VueRouter from 'vue-router'
// 引入token
// import { getToken } from '@/utils/storage'
// 一级路由
import Login from '@/views/login'
import Layout from '@/views/layout'
import Register from '@/views/register'
import Collect from '@/views/myCollect'
import Hire from '@/views/myHire'
import City from '@/views/cityList'
import MapFind from '@/views/mapFind'
import PushHouse from '@/views/pushHouse'
// 二级路由
import Index from '@/views/index'
import Find from '@/views/find'
import News from '@/views/news'
import My from '@/views/my'
Vue.use(VueRouter)

const router = new VueRouter({
  routes: [
    { path: '/login', component: Login },
    { path: '/register', component: Register },
    { path: '/collect', component: Collect },
    { path: '/hire', component: Hire },
    { path: '/cityList', component: City },
    { path: '/MapFind', component: MapFind },
    { path: '/pushHouse', component: PushHouse },
    {
      path: '/',
      component: Layout,
      // 重定向 加载直接显示这个页面
      redirect: '/index',
      children: [
        { path: '/index', component: Index },
        { path: '/find', component: Find },
        { path: '/news', component: News },
        { path: '/my', component: My }
      ]
    }
  ]
})

// 全局前置守卫
// const whiteList = ['/login', '/register']
// router.beforeEach((to, from, next) => {
//   const token = getToken()
//   if (token) {
//     next()
//   } else {
//     if (whiteList.includes(to.path)) {
//       next()
//     } else {
//       next('/login')
//     }
//   }
// })

export default router
